﻿using System;

namespace KTOP.Core.Domain.Matrix
{
    public class CMatrix : MatrixWithSumms
    {
        public CMatrix(int[][] matrix)
            : base(matrix)
        {
        }

        public static CMatrix Create(RMatrix rMatrix, DMatrix dMatrix, int[] renamingTable)
        {
            if (rMatrix.Size != dMatrix.Size) throw new ArgumentException("dMatrix");
            if (renamingTable.Length != dMatrix.Size) throw new ArgumentException("renamingTable");

            var cMatrix = CreateEmptyMatrix(rMatrix.Size);

            for (var row = 0; row < rMatrix.Size; row++)
                for (var col = 0; col < rMatrix.Size; col++)
                    cMatrix[row][col] = rMatrix[row, col]*dMatrix[renamingTable[row], renamingTable[col]];

            return new CMatrix(cMatrix);
        }
    }
}
